﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Pitaya_IDE
{
    public class CtrlBar : Panel
    {
        FileTitleBar fileTitleBar;
        List<Label> labels = new List<Label>();

        public CtrlBar(FileTitleBar _fileTitleBar)
        {
            fileTitleBar = _fileTitleBar;
            BackColor = fileTitleBar.BackColor;

            Label label = new Label()
            {
                Size = new Size(38, 38),
                Location = new Point(8, (fileTitleBar.Size.Height - 38) / 2),
                BackColor = fileTitleBar.BackColor,
                Image = AllImage.FImage_file[12],
                Cursor = Cursors.Hand,
            };

            

            label.MouseDown += new MouseEventHandler(More_MouseDown);
            label.MouseUp += new MouseEventHandler(More_MouseUP);
            label.MouseEnter += new EventHandler(More_MouseEnter);
            label.MouseLeave += new EventHandler(More_MouseLeave);

            AddBtu(label);
        }

        public void AddBtu(Label panel)
        {
            labels.Add(panel);
            this.Controls.Add(panel);

            Focus1 = true;
        }

        private bool focus1 = false;  //表示当前是否拥有焦点  

        public bool Focus1
        {
            get => focus1;
            set
            {
                focus1 = value;
                RefreshLocation();
            }
        }

        public void RefreshLocation()
        {
            if (focus1)
            {
                Size = new Size(8 + 38 * labels.Count + 6 * (labels.Count - 1) + 20,
                                    fileTitleBar.Size.Height);
                Location = new Point(fileTitleBar.Size.Width - Size.Width, 0);

                for (int i = 0; i < labels.Count; i++)
                {
                    Label label2 = labels[i];
                    label2.Visible = true;
                    label2.Location = new Point(8 + (labels.Count - 1 - i) * (38 + 6), (Height - 38) / 2);
                }
            }
            else
            {
                Size = new Size(8 + 38 + 20, fileTitleBar.Size.Height);
                Location = new Point(fileTitleBar.Width - Size.Width, 0);

                labels[0].Location = new Point(8, (Height - 38) / 2);

                for (int i = 1; i < labels.Count; i++)
                {
                    labels[i].Visible = false;
                }
            }
        }

        private bool Mouseflag = false;
        private void More_MouseUP(object sender, EventArgs e)
        {
            if (Mouseflag)
            {
                
            }
            Mouseflag = false;
        }
        private void More_MouseDown(object sender, EventArgs e)
        {
            Mouseflag = true;
        }
        
        private void More_MouseEnter(object sender, EventArgs e)
        {
            Label label = (Label)sender;
            label.Image = AllImage.FImage_file[13];
        }
        private void More_MouseLeave(object sender, EventArgs e)
        {
            Label label = (Label)sender;
            label.Image = AllImage.FImage_file[12];
        }
    }

}